package com.example.expandablelistview.activity;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;

public class SaveState01 extends Activity {
	private StateView vw;
	private int x;
	private int y;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.d("aaa", "onCreate");
		super.onCreate(savedInstanceState);
		//임시저장
		if (savedInstanceState==null){
			x = 50;
		}else{
			x = savedInstanceState.getInt("x");
		}
		// 영구저장
		SharedPreferences pref = getSharedPreferences("SaveState", 0);
		y = pref.getInt("y", 50);
		
		vw = new StateView(this);
		vw.setPtX(x);
		vw.setPtY(y);
		
		vw.setFocusable(true);
		vw.setFocusableInTouchMode(true);
		setContentView(vw);
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		SharedPreferences pref = getSharedPreferences("SaveState", 0);
		SharedPreferences.Editor edit = pref.edit();
		edit.putInt("y", (int)vw.getPtY());
		edit.commit();
	}
	
	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		Log.d("aaa", "onRestoreInstanceState");
		super.onRestoreInstanceState(savedInstanceState);
		vw.setPtX(savedInstanceState.getInt("x"));
		vw.invalidate();
	}
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putInt("x", vw.getPtX());
	}
	
}
